package com.rx.stang.service.proxy;

import com.rx.core.base.RxBaseData;
import com.rx.core.enm.HANDLER_TYPE;
import com.rx.core.service.StandardService;
import com.rx.core.util.EmptyChecker;
import com.rx.core.util.RxUtil;
import com.rx.stang.service.FeignUuaService;
import com.rx.stang.vo.PermisionRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rx.uua.vo.UuaRelUserColumnist;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class STOutProxyService {

    @Autowired
    StandardService standardService;

    @Autowired
    FeignUuaService feignOrgInfoService;

    public List<PermisionRequest> permisionRequest(PermisionRequest data){

        try {
            UuaRelUserColumnist uuaRelUserColumnist = (UuaRelUserColumnist) RxBaseData.create(UuaRelUserColumnist.class, HANDLER_TYPE.SINGLE_LIST);
            RxUtil.copyProperties(data,uuaRelUserColumnist);
            uuaRelUserColumnist.getHandlerController().onlyDefault();

            List<UuaRelUserColumnist> forbiddenList = RxUtil.result(standardService.searchList(uuaRelUserColumnist));
            if(EmptyChecker.isEmpty(forbiddenList)){
                return Collections.emptyList();
            }
            List<PermisionRequest> permisionRequestList = new ArrayList<>();
            for (UuaRelUserColumnist uuaRelUserColumnist_ : forbiddenList) {
                PermisionRequest permisionRequest = new PermisionRequest();
                permisionRequest.setTitle(uuaRelUserColumnist_.getTitle());
                permisionRequest.setUserBid(uuaRelUserColumnist_.getUserBid());
                permisionRequestList.add(permisionRequest);
            }
            return permisionRequestList;

        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

        return feignOrgInfoService.searchColumnAuth(data);
    }

}
